{%extend name="Public:layout"/%}

{%block name="title"%}
<h2 class="mb20">
    微信公众号
</h2>
{%/block%}

{%block name="contents"%}
<form action="{%:U('/admin/weixin/uploadarticles')%}" onsubmit="return false" stverify="true" erroappend="true" method="post"
      beforeSubFun="" enctype="multipart/form-data">
    <table class="table table-listing">
        <tr>
          <td>
              <select class="st-dropdown" name="type1" data-config="zIndex:9001">
                  <option value="news">资讯ID</option>
                  <option value="spoiler">剧透ID</option>
                  <option value="egg">彩蛋ID</option>
              </select>
              <input class="input input-small" type="text" name="id1" value="" />
              摘要：<textarea rows="1" cols="60" name="digest1"></textarea>
              <br />
              <select class="st-dropdown" name="type2" data-config="zIndex:9001">
                  <option value="news">资讯ID</option>
                  <option value="spoiler">剧透ID</option>
                  <option value="egg">彩蛋ID</option>
              </select>
              <input class="input input-small" type="text" name="id2" value="" />
              摘要：<textarea rows="1" cols="60" name="digest2"></textarea>
              <br />
              <select class="st-dropdown" name="type3" data-config="zIndex:9001">
                  <option value="news">资讯ID</option>
                  <option value="spoiler">剧透ID</option>
                  <option value="egg">彩蛋ID</option>
              </select>
              <input class="input input-small" type="text" name="id3" value="" />
              摘要：<textarea rows="1" cols="60" name="digest3"></textarea>
              <br />
              <select class="st-dropdown" name="type4" data-config="zIndex:9001">
                  <option value="news">资讯ID</option>
                  <option value="spoiler">剧透ID</option>
                  <option value="egg">彩蛋ID</option>
              </select>
              <input class="input input-small" type="text" name="id4" value="" />
              摘要：<textarea rows="1" cols="60" name="digest4"></textarea>
              <br />
              <select class="st-dropdown" name="type5" data-config="zIndex:9001">
                  <option value="news">资讯ID</option>
                  <option value="spoiler">剧透ID</option>
                  <option value="egg">彩蛋ID</option>
              </select>
              <input class="input input-small" type="text" name="id5" value="" />
              摘要：<textarea rows="1" cols="60" name="digest5"></textarea>
              <br />
              <select class="st-dropdown" name="type6" data-config="zIndex:9001">
                  <option value="news">资讯ID</option>
                  <option value="spoiler">剧透ID</option>
                  <option value="egg">彩蛋ID</option>
              </select>
              <input class="input input-small" type="text" name="id6" value="" />
              摘要：<textarea rows="1" cols="60" name="digest6"></textarea>
              <br />
              <select class="st-dropdown" name="type7" data-config="zIndex:9001">
                  <option value="news">资讯ID</option>
                  <option value="spoiler">剧透ID</option>
                  <option value="egg">彩蛋ID</option>
              </select>
              <input class="input input-small" type="text" name="id7" value="" />
              摘要：<textarea rows="1" cols="60" name="digest7"></textarea>
              <br />
              <select class="st-dropdown" name="type8" data-config="zIndex:9001">
                  <option value="news">资讯ID</option>
                  <option value="spoiler">剧透ID</option>
                  <option value="egg">彩蛋ID</option>
              </select>
              <input class="input input-small" type="text" name="id8" value="" />
              摘要：<textarea rows="1" cols="60" name="digest8"></textarea>
          </td>
        </tr>
        <tr>
            <td>
                <input class="btn btn-blue" type="submit" value="同步到微信公众号" />
            </td>
        </tr>
    </table>
</form>
<h2 class="m20">
    新浪微博
</h2>
<table class="table table-listing">
    <tr>
        <td>
            <select class="st-dropdown" name="typec" data-config="zIndex:9001">
                <option value="news">资讯ID</option>
                <option value="spoiler">剧透ID</option>
                <option value="egg">彩蛋ID</option>
            </select>
            <input class="input input-small" type="text" name="idc" value="" />
            摘要：<textarea rows="1" cols="60" name="digestc"></textarea>

            <span id="js_publishInput" {%eq name="info['auto_publish_time']" value="0"%}style="display:none"{%/eq%}>
            <input class="input" type="text" name="auto_publish_time" id="_auto_calender" value="{%php%}echo date('Y-m-d'){%/php%}"/>
            <select class="st-dropdown" name="auto_publish_hour" data-config="zIndex:9001">
                {%volist name="auto_publish_hours" id="vo"%}
                <option value="{%$vo.time%}" {%if condition="$vo.time == date('H:i', $info['auto_publish_time'])"%}selected{%/if%}>{%$vo.text%}</option>
                {%/volist%}
            </select>
            </span>
            <a class="btn btn-blue" href="javascript:;" onclick="ST.todo('to_weibo', '1')">定时发微博</a>
            <a class="btn btn-blue" href="javascript:;" onclick="ST.todo('to_weibo', '0')">立即发微博</a>
         </td>
    </tr>
</table>
<h2 class="m20"></h2>
<table class="table table-listing table-hovered">
    <thead class="thead-gray">
    <tr>
        <th>类型</th>
        <th>ID</th>
        <th class="span6">摘要</th>
        <th>定时时间</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {%notempty name="list"%}
    {%foreach name="list" item="vo" %}
    {%php%}$myData=json_decode($vo['data'],1);{%/php%}
    <tr>
        <td>{%$myData.type%}</td>
        <td>{%$myData.id%}</td>
        <td>{%$myData.digest%}</td>
        <td>{%$vo.auto_publish_time|date='Y-m-d H:i',###%}</td>
        <td>{%eq name="vo['status']" value="1"%}<font color="green">已处理</font>{%else/%}待执行{%/eq%}</td>
        <td>
            <a href="javascript:;" onclick="ST.todo('del','{%$vo.id%}')" class="mr5"><i class="icon i-del"></i></a>
        </td>
    </tr>
    {%/foreach%}
    {%/notempty%}
    </tbody>
</table>
<h2 class="m20"></h2>
<div class="paging">{%$page%}</div>
{%/block%}

{%block name="js"%}
<script type="text/plain" id="js_editor_upload_egg" style="display:none;"></script>
<script src="__JAVASCRIPT__/ueditor/ueditor.config.js"></script>
<script src="__JAVASCRIPT__/ueditor/ueditor.all.min.js"></script>
<script src="__JAVASCRIPT__/ST.Calender.js"></script>
<script type="text/javascript">
    var this_year = new Date().getFullYear();
    var _auto_calender = new ST.Calender("_auto_calender", "", this_year, this_year);
    _auto_calender.timePicker = false;

    var js_editor_upload_egg = UE.getEditor('js_editor_upload_egg', {serverUrl: "{%:U('admin/index/upload?imageActionName=upload_caidan')%}"});
    js_editor_upload_egg.ready(function () {
        js_editor_upload_egg.hide();//隐藏编辑器
        js_editor_upload_egg.addListener('beforeInsertImage', function (t, arg) {
            $('input[name='+ST.upImageEggInput+']').val(arg[0].src);
            $('input[name='+ST.upImageEggInput+']').parent().find('img').attr('src', arg[0].src);
        });
        js_editor_upload_egg.addListener('afterUpfile', function (t, arg) {
        });
    });
    $.extend(ST, {
        upImageEggInput: '',
        upImageEgg: function(input) {
            ST.upImageEggInput = input;
            var myImage = js_editor_upload_egg.getDialog("insertimage");
            myImage.open();
        },
        to_weibo: function(timing) {
            var myData = {
                type: $('select[name=typec]').val(),
                id: $('input[name=idc]').val(),
                digest: $('textarea[name=digestc]').val(),
                auto_publish_time: null,
                auto_publish_hour: null
            };
            if (timing == 1) {
                myData.auto_publish_time = $('input[name=auto_publish_time]').val();
                myData.auto_publish_hour = $('select[name=auto_publish_hour]').val();
            }
            console.log(myData);
            ST.execAJAX({
                url: "{%:U('/admin/weixin/to_weibo')%}",     //服务端请求地址
                params: myData,
                hasconfirm: false,
                succFun: function (j) {  //成功后的回调方法：刷新页面
                    if (!j) return;
                    location.reload();

                },
                erroFun: function (j) {
                    ST.alert(
                            j.data,
                      '',
                      function(){},
                      240,
                      180
                    );
                }
            });
        },
        del: function (id) {
            ST.execAJAX({
                url: "{%:U('/admin/weixin/del_weibo')%}",     //服务端请求地址
                params: {id: id},       //发送到服务端的参数（如：{myparam:1}）
                massage: '确定删除吗？',       //提示信息（仅hasconfirm为true时有用）
                hasconfirm: true,       //提交前是否显示确认框
                succFun: function (j) {  //成功后的回调方法：刷新页面
                    if (!j) return;
                    if (j.data && j.data.url) {
                        location.href = j.data.url;
                    } else {
                        ST.reload();
                    }
                }
            });
        }
    });
    ST.init();
</script>
{%/block%}
